<?php
error_reporting(0);
define('IN_PISCES',true);
define('PISCES_BASE_URL','http://pisces/');
date_default_timezone_set('Etc/GMT-8');

$piscesHome 	= 'D:/www/pisces/web/';

$projHome		= $piscesHome.'pisces/';
include $projHome . 'framework/runtime/Lotus.php';

$lotus = new Lotus();

$lotus->option['proj_dir'] = $projHome.'code/';

$lotus->option['app_dir'] = $projHome.'code/app/';

$lotus->option['app_name'] = 'frontend';

$lotus->option['load_function'] = true;
$lotus->option['runtime_filemap'] = true;

$lotus->mvcMode = false;
$lotus->devMode = true;
$lotus->init();

function taozhangmen_product_list($cat,$keyword,$ids,$num,$cache=86400,$position='dede_home',$fields='num_iid,title,pic_url,item_location,price,commission'){
	$con	= array();
	if(is_numeric($cat) && $cat>0)
	{
		$con['cid']	= $cat;
	}
	if(!empty($keyword))
	{
		$con['keyword']	= C('CommonFunction')->getRandKeyword($keyword);
	}
	if(!empty($ids))
	{
		$con['ids']		= $ids;
	}
	if(!is_numeric($num) || $num<=0 || $num>20)
	{
		$num = 10;
	}
	$con['page_size']	= $num;
	if(empty($fields))
	{
		$fields	= array();
	}
	else
	{
		$fields	= explode(',',$fields);
	}
	$ret = C('ProductService')->getList($con,$fields,$cache,$position);
	if(!empty($ret))
	{
		$returnSetting = C('SettingService')->get('return_setting',true);
		$url	= C('LtUrl');
		$cf		= C('CommonFunction');
		foreach($ret as &$rv)
		{
			if($returnSetting['rate']>0 && array_key_exists('commission',$rv))
			{
				$rv['commission']	= round($rv['commission']*$returnSetting['rate']/100,2);
			}
			$rv['detail_link']	= $url->generateOutsiteUrl(PISCES_BASE_URL,'Default','View',array('id'=>$cf->getId($rv['num_iid'])));
			$rv['click_link']	= $url->generateOutsiteUrl(PISCES_BASE_URL,'Default','Click',array('id'=>$rv['num_iid']));
			if(array_key_exists('pic_url',$rv))
			{
				$rv['image']	= base64_encode($rv['pic_url']);
				$rv['image_b']	= base64_encode($rv['pic_url'].'_b.'.$cf->getFileExt($rv['pic_url']));
			}
		}
	}
	
	return $ret;
}